#!/bin/bash

ROOT_UID=0
#LOG_DIR=/var/log
LOG_DIR=/home/wzq/work/workspace/cvs/javascript-snippet/shell
LINES=50
E_XCD=86
E_NOTROOT=87

if [ "$UID" -ne "$ROOT_UID" ] ; then
	echo "must be root to run this script"
	exit $E_NOTROOT
fi

# if [ -n "$1" ]; then
# 	lines=$1
# else
# 	lines=$LINES
# fi

E_WRONGARGS=85
case "$1" in
	"") lines=$LINES;;
	*[!0-9]*) echo "arguments must be number";
		exit $E_WRONGARGS;;
	*) lines=$1;;
esac

cd $LOG_DIR
if [ `pwd` != "$LOG_DIR" ] ; then
	echo "cannot change to $LOG_DIR"
	exit $E_XCD
fi

tail -n $lines messages > mesg.temp
mv mesg.temp messages
cat /dev/null > wtmp # :>wtmp or >wtmp
echo "Log files cleaned up"
exit 0